package cn.edu.scau.cmi.tangqingning.tools;

import javax.servlet.http.HttpServletRequest;

/**
 * StringUtil是一个工具类，该类中定义了两个可判断字符串是否为空的方法。
 * 
 * @author 庄桂满
 *
 */
public class StringUtil {
	/**
	 * 判断字符串是否为空
	 * @param str String
	 * @return true或false
	 */
	public static boolean isEmpty(String str) {
		if ("".equals(str) || str == null) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 得到小数点后两位的数
	 * @param x double
	 * @return result 
	 */
	public static double toDecimals(double x) {
		double result = ((int) (x * 100)) / 100.0;
		return result;
	}

	/**
	 * 获取用户真实ip
	 * @param request HttpServletRequest
	 * @return request.getHeader("x-forwarded-for")
	 */
	public static String getRemortIP(HttpServletRequest request) {

		if (request.getHeader("x-forwarded-for") == null) {

			return request.getRemoteAddr();
		}
		return request.getHeader("x-forwarded-for");
	}
}
